Skip to content

fix(router): query params not being saved #2062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 5, 2020

Conversation

edusperoni
Copy link
Collaborator

@edusperoni edusperoni commented Nov 11, 2019

PR Checklist

What is the current behavior?

Query parameters are not preserved when navigating back.

The router state consists only of UrlSegmentGroup, which does not store any query parameters.

What is the new behavior?

The state now stores the QueryParams and properly restores them.

Fixes #1509.


Please ignore the tests I've done in e2e, I'll remove them when work is done.

Tests are passing, additional tests needed for modal and params preservation

Possible alternative:
store queryParams[] in NSLocationStrategy (since the outlet itself does not have queryParams, but the page does) and push to it at every pushState and pop at every popState, but how would it work with replaceState?

@edusperoni edusperoni changed the title WIP: fix(router): query params not being saved fix(router): query params not being saved Nov 18, 2019
@edusperoni
Copy link
Collaborator Author

After some testing, I believe this is ready for review (e2e changes need to be reverted before merge)

GlThibault
GlThibault previously approved these changes Dec 26, 2019
@dtopuzov
Copy link
Contributor

dtopuzov commented Jan 2, 2020

test

causes issues with `npm install`
const isNewPage = outlet.states.length === 0;
const lastState = outlet.states[outlet.states.length - 1];
const equalStateUrls = outlet.containsTopState(currentSegmentGroup.toString());

const locationState: LocationState = {
segmentGroup: currentSegmentGroup,
isRootSegmentGroup: false,
isPageNavigation: isNewPage
isPageNavigation: isNewPage,
queryParams: {...queryParams}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be best to use some protection here in case queryParams comes in null or undefined?

queryParams: { ...(queryParams || {}) }

const pathByOutlets = this.getPathByOutlets(segmentGroup);
const newOutlet = new Outlet(outletKey, path, pathByOutlets, modalNavigation);

const locationState: LocationState = {
segmentGroup: segmentGroup,
isRootSegmentGroup: false,
isPageNavigation: true // It is a new OutletNode.
isPageNavigation: true, // It is a new OutletNode.
queryParams: {...queryParams}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

queryParams: { ...(queryParams || {}) }

@NathanWalker NathanWalker merged commit 221e404 into NativeScript:master Jun 5, 2020
@NathanWalker
Copy link
Contributor

Thank you for the contribution @edusperoni 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserving the existing queryParams on back navigation
5 participants